package main

import "fmt"

var balance = [5]float32{1000.0, 2.0, 3.4, 7.0, 50.0}

func main()  {
	fmt.Println(balance)
	var j int
	/* 输出每个数组元素的值 */
	for j = 0; j < len(balance); j++ {
		fmt.Println("Element[%d] = %d", j, balance[j] )
	}

	main1()

	/* 数组长度为 5 */
	var  balance = []int {1000, 2, 3, 17, 50}
	var avg float32

	/* 数组作为参数传递给函数 */
	avg = getAverage( balance, len(balance)) ;

	/* 输出返回的平均值 */
	fmt.Printf( "平均值为: %f ", avg );
}


func main1() {
	/* 数组 - 5 行 2 列*/
	var a = [5][2]int{ {0,0}, {1,2}, {2,4}, {3,6},{4,8}}
	var i, j int

	/* 输出数组元素 */
	for  i = 0; i < 5; i++ {
		for j = 0; j < 2; j++ {
			fmt.Printf("a[%d][%d] = %d\n", i,j, a[i][j] )
		}
	}
}

func getAverage(arr []int, size int) float32 {
	var i,sum int
	var avg float32

	for i = 0; i < size;i++ {
		sum += arr[i]
	}

	avg = float32(sum) / float32(size)

	return avg;
}